package com.prabodha.fruitmap;

import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;

import com.webService.Webservice;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Toast;

public class Advertise extends Activity{
	SoapObject request;
	SoapSerializationEnvelope envelope;
	String fruit;
	int quantity;
	int unit_price;
	int save;
	String expiry_date;
	String user_id;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_advertise);
		Button submit=(Button) findViewById(R.id.add_submit);
		final EditText frui=(EditText) findViewById(R.id.fruit);
		final EditText quantit=(EditText) findViewById(R.id.quantity);
		final EditText sav=(EditText) findViewById(R.id.save);
		final EditText unit_pric=(EditText) findViewById(R.id.unit_price);
		final DatePicker expires=(DatePicker)findViewById(R.id.datePicker1);
		
		submit.setOnClickListener(new OnClickListener() {		
			public void onClick(View v) {
				
				fruit=frui.getText().toString();
				quantity=Integer.parseInt(quantit.getText().toString());
				save=Integer.parseInt(sav.getText().toString());
				unit_price=Integer.parseInt(unit_pric.getText().toString());
				expiry_date=""+expires.getYear()+"-"+expires.getMonth()+"-"+expires.getDayOfMonth();
				user_id=MainActivity.userid;
				
				Log.d("llllllllllllllllllllllllllname", fruit);

				
				
				try{
	            	Webservice wb = new Webservice();
	           	 
	            	wb.METHOD_NAME = "advertise";
	            	wb.SOAP_ACTION = "http://fruitMap.com/"+wb.METHOD_NAME;
	            	 
	            	 request =wb.getRequest();
	            	 request.addProperty("user_id",user_id);
	            	 request.addProperty("fruit",fruit);
	            	 request.addProperty("quantity",quantity);
	            	 request.addProperty("save",save);
	            	 request.addProperty("unit_price",unit_price);
	            	 request.addProperty("expiry_date",expiry_date);
	            	 
	            	 
	            	 
	            	 envelope = wb.setRequestAndGetEnvilop(request); 
	            	 SoapPrimitive soap = wb.getPrimitive(envelope);
	            	 
	            	 if(soap.toString().trim().equals("true")){
	            		//showDialog("Successfully login !");
	            		
	            	Toast.makeText(Advertise.this, "Ad Successfully added", Toast.LENGTH_LONG).show();
	            		// Toast.makeText(.this, "Successfully added", Toast.LENGTH_LONG).show();
//	            		 Intent in = new Intent();
//	            		 in.setClass(this,Home.class);
//	            		 startActivity(in);
	            		// new StoreMapVariable().setVaraible();
	            		//Toast.makeText(this,"true",Toast.LENGTH_SHORT).show(); 
	            	 }
	            	 else{
	            		//showDialog("Enter valied User name and password  !");
	            		//Toast.makeText(this,"false",Toast.LENGTH_SHORT).show();
	            	 }
	            
	            }catch(Exception ex){
	            	ex.printStackTrace();
	            	
	            }
				
				
			}
		});
		
	}
	
}
